<template>
	<view>
		<view class="bg" v-if="list.length">
			<view class="mode" style="color: #666666;line-height: 60rpx;">
				<view style="font-size: 32rpx;font-weight: bold;">
					我的车牌
				</view>
				<view v-for="(item,index) in list" :key="index" :class="item.cn.length==7?'b':'g'" class="list">
					<view class="u-flex u-row-between">
						<view>{{item.cn.length==7?'普通车牌':'新能源车牌'}}</view>
						<view @click="closeBind(item)">解绑</view>
					</view>
					<view style="font-size: 32rpx;font-weight: bold;">{{item.cn}}</view>
				</view>

			</view>
		</view>


		<view class="bottomFix">
			<u-button @click="submit" type="primary" :custom-style="{width:'600rpx',background:'#0064C6'}"
				shape="circle">
				<u-icon name="plus" :custom-style="{marginRight:'20rpx'}"></u-icon>
				添加车牌
			</u-button>
		</view>

		<view class="empty">
			<u-empty mode="list" v-if="!list.length" text="暂无车牌"></u-empty>
		</view>


		<u-toast ref="uToast" />

	</view>
</template>

<script>
	export default {
		data() {
			return {
				list: []
			}
		},
		onLoad(options) {

		},
		onShow() {
			this.jiazai()
		},
		methods: {
			submit() {
				uni.navigateTo({
					url: "./index"
				})
			},
			jiazai() {
				this.$u.post('/api/user/cn', {}).then(res => {
					this.list = res;
				}).catch(err => {})

			},
			closeBind(item) {
				uni.showModal({
					title: "温馨提示",
					content: "是否确认解绑车牌?",
					success: (res) => {
						if (res.confirm) {
							this.$u.post('/api/user/unbindCn', {
								cn_id: item.id
							}).then(res => {
								this.$refs.uToast.show({
									title: "解绑成功",
									type: 'success',
									callback: () => {
										this.jiazai()
									}

								})

							}).catch(err => {})
						}
					},
				})

			}
		}
	}
</script>

<style>
	.bg {
		width: 750rpx;
		height: 200rpx;
		background: linear-gradient(-5deg, #0064C6, #2190FB);
		display: inline-block;
	}

	.mode {
		width: 695rpx;

		background: #FFFFFF;
		box-shadow: 6rpx 8rpx 8rpx 1rpx rgba(201, 201, 201, 0.19);
		border-radius: 12rpx;
		background: #FFFFFF;
		margin: 80rpx auto;
		padding: 30rpx;
	}

	.list {
		padding: 20rpx;
		color: #fff;
		border-radius: 20rpx;
		margin-top: 20rpx;
	}

	.b {
		background: linear-gradient(94deg, #4BA6FF 0%, #0064C6 100%);
	}

	.g {
		background: linear-gradient(90deg, #21D676 0%, #0BBC75 100%);
	}
</style>
